package com.ronan.imweb.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ronan.common.pojo.business.AddGVReq;
import com.ronan.imweb.dao.GameValueDao;
import com.ronan.imweb.model.GameValue;
import com.ronan.imweb.service.GameValueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * FileName    : com.withufuture.imweb.service.impl.buiness
 * Description :
 *
 * @author : ronan
 * @version : 1.0
 * Create Date : 2021/3/18 14:48
 **/
@Slf4j
@Service
public class GameValueServiceImpl implements GameValueService {

    @Autowired
    private GameValueDao gameValueDao;

    @Override
    public void addGV(AddGVReq req) {
        log.info("[AddGVReq] => {}",req.toString());
        // step1.查询数据库是否有当前用户的数据,有则更新,无则添加
        GameValue gv = new GameValue();
        gv.setAccid(req.getAccid());
        // 不知道为什么,就感觉很拉跨,算了,写个测试例子而已
        GameValue res = gameValueDao.selectByParams(gv);
        if (res != null) {
            gv.setMood(req.getMood());
            gv.setWear(req.getWear());
            gv.setWhite(req.getWhite());
            gameValueDao.updateBySelective(gv);
        }else {
            gv.setId(IdUtil.fastSimpleUUID());
            gv.setMood(req.getMood());
            gv.setWear(req.getWear());
            gv.setWhite(req.getWhite());
            gameValueDao.insert(gv);
        }
    }
}
